/**
 * 面包屑
 */

const arr=sessionStorage.getItem('breadcrumb')?JSON.parse(sessionStorage.getItem('breadcrumb') as string):[]

const breadCrumbStore = {
  namespaced: true,
  state: {
    list:arr
  },
  mutations: {
    setBreadCrumb(state: any, data: any) {
      // 如果是侧边栏 清除路由栈
      if (data.meta.isRoot) {
        let obj = {
          name: data.matched[0].meta.title,
          path:''
        }
        state.list=[obj]
      }

      //判断路由栈中是否包含当前路由
      let flag:boolean = state.list.some((item: any) => item.path === data.fullPath)
      if (!flag) {
        state.list.push({name:data.meta.title,path:data.fullPath})
      }
      

      sessionStorage.setItem('breadcrumb',JSON.stringify(state.list))
    }
  }
}

export default breadCrumbStore